package com.cn.thread;

import java.util.concurrent.*;

/**
 * @author hels
 * @version 1.0
 * @date 2022/3/8 10:41
 */
public class ThreadPoolDemo3 {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        // https://www.jianshu.com/p/f030aa5d7a28
        // LinkedBlockingQueue（无界阻塞队列）如果任务提交速度大于任务处理速度，会造成队列大量阻塞。OOM，FixedThreadPool任务执行无序
        ExecutorService service = Executors.newFixedThreadPool(2);

        Callable<Integer> c = new myCallAble2(12, 23);
        Callable<Integer> c2 = new myCallAble2(12, 3);

        Future<Integer> result = service.submit(c2);
        Integer integer1 = result.get();

        System.out.println(integer1.toString());
    }
}

class myCallAble2 implements Callable<Integer> {
    int x,y;
    public myCallAble2(int x, int y) {
        this.x = x;
        this.y = y;
    }

    @Override
    public Integer call() throws Exception {
        return x + y;
    }
}



